package io.renren.modules.generator.controller;

import java.util.List;
import java.util.Map;

import io.renren.modules.generator.entity.SpringLambEntity;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.renren.modules.generator.entity.WarnEntity;
import io.renren.modules.generator.service.WarnService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;
import io.renren.common.utils.R;




/**
 * 载畜量预警
 * 
 * @author chenshun
 * @email sunlightcs@gmail.com
 * @date 2018-05-02 13:20:17
 */
@RestController
@RequestMapping("warn")
public class WarnController {
	@Autowired
	private WarnService warnService;
	
	/**
	 * 列表
	 */
	@RequestMapping("/list")
	@RequiresPermissions("warn:list")
	public R list(@RequestParam Map<String, Object> params){
		//查询列表数据
        Query query = new Query(params);

		List<WarnEntity> warnList = warnService.queryList(query);
		int total = warnService.queryTotal(query);
		
		PageUtils pageUtil = new PageUtils(warnList, total, query.getLimit(), query.getPage());
		
		return R.ok().put("page", pageUtil);
	}
	
	
	/**
	 * 信息
	 */
	@RequestMapping("/info/{id}")
	@RequiresPermissions("warn:info")
	public R info(@PathVariable("id") Integer id){
		WarnEntity warn = warnService.queryObject(id);
		
		return R.ok().put("warn", warn);
	}
	
	/**
	 * 保存
	 */
	@RequestMapping("/save")
	@RequiresPermissions("warn:save")
	public R save(@RequestBody WarnEntity warn){
		warnService.save(warn);
		
		return R.ok();
	}
	
	/**
	 * 修改
	 */
	@RequestMapping("/update")
	@RequiresPermissions("warn:update")
	public R update(@RequestBody WarnEntity warn){
		warnService.update(warn);
		
		return R.ok();
	}
	
	/**
	 * 删除
	 */
	@RequestMapping("/delete")
	@RequiresPermissions("warn:delete")
	public R delete(@RequestBody Integer[] ids){
		warnService.deleteBatch(ids);
		
		return R.ok();
	}

	@RequestMapping("/warnlist")
	@RequiresPermissions("warn:list")
	public R timelist(@RequestParam Map<String, Object> params){
		//查询列表数据
		Query query = new Query(params);
		System.out.println("得到的参数："+query);
		List<WarnEntity> animalpriceList = warnService.warnList(query);

		int total = warnService.warnTotal(query);

		PageUtils pageUtil = new PageUtils(animalpriceList, total, query.getLimit(), query.getPage());

		return R.ok().put("page", pageUtil);
	}
	
}
